
class_name UnitInfoPlan
extends ColorRect




@onready var icon = $CR/IconCR/Icon
@onready var info = $CR/InfoCR/Info
@onready var unit_name = $CR/Name
@onready var unit_hpep = $CR/HPEP

# 当前显示的 unit
var current_unit: Unit = null




func start() -> void:
	show()
	set_process(true)




func end() -> void:
	hide()
	set_process(false)




func update(_unit: Unit) -> void:
	if is_instance_valid(_unit):
		if current_unit != _unit:
			current_unit = _unit
	else:
		return
	
	var property: UnitProperty = _unit.property
	# 设置 Icon
	icon.texture = load(_unit.profile_photo)
	icon.modulate = _unit.icon.modulate
	# 显示单位信息
	unit_name.text = property.unit_name
	unit_hpep.text = \
		"HP:" + str(property.current_hp) + \
		"/" + str(property.hp) + \
		"    HP自然恢复:" + str(property.hp_recover) + \
		"/" + str(property.hp_cycle) + \
		"\nEP:" + str(property.current_ep) + \
		"/" + str(property.ep) + \
		"    EP自然恢复:" + str(property.ep_recover) + \
		"/" + str(property.ep_cycle)
	info.text = \
		"普通攻击:" + str(property.ap_ordinary) + \
		"\t\t特殊攻击:" + str(property.ap_special) + \
		"\n普通抗性:" + str(property.dp_ordinary) + \
		"\t\t法术抗性:" + str(property.dp_special) + \
		"\t\t优先度:" + str(property.priority) + \
		"\t\t速度:" + str(property.sp)
	show()




func _process(_delta: float) -> void:
	update(current_unit)
